#-------------------------------------------------
# reference :
#   https://libaineu2004.blog.csdn.net/article/details/89366925
#   https://juejin.cn/post/6963596901447335944
#-------------------------------------------------

#-------------------------------------------------
# Configure compilation
#-------------------------------------------------

win32{
    QMAKE_CXXFLAGS += -march=i686
}

#Cancel warning of unused function parameters
QMAKE_CXXFLAGS +=  -Wno-unused-parameter

# Tell qmake to set the compiler to output warning messages
CONFIG  += warn_on

#-------------------------------------------------
# If it exists, it means that the application outputs debugging information
# If you need to enable the http request debug log then with this define
#-------------------------------------------------

CONFIG(debug, debug|release) {
    DEFINES += MAPLE_MODE_DEBUGGING
} else {
    #DEFINES += MAPLE_MODE_DEBUGGING
}

#-------------------------------------------------
# cpu architecture for application x86_64 / arm / mips
#-------------------------------------------------

contains(QT_ARCH, arm64) {
    DEFINES += MAPLE_CPU_ARCH_ARM
}
else{
    contains(QT_ARCH, mips64) {
        DEFINES += MAPLE_CPU_ARCH_MIPS
    }
    else{
        DEFINES += MAPLE_CPU_ARCH_X86_64
    }
}

#-------------------------------------------------
# Configure compilation output directory
#-------------------------------------------------

build_type =
CONFIG(debug, debug|release) {
    build_type = debug
} else {
    build_type = release
}

DESTDIR     = $$OUT_PWD/$$build_type
OBJECTS_DIR = temp/obj  # ./obj
MOC_DIR     = temp/moc  # ./moc
RCC_DIR     = temp/rcc  # ./rcc
UI_DIR      = temp/ui   # ./ui

#message($$QT_ARCH)
#message($$DEFINES)

#-------------------------------------------------
# copy config file ： study：https://www.cnblogs.com/brifuture/p/8635317.html
#-------------------------------------------------

defineTest(cp_to_destdir) {
    #config file list
    files = $$1
    #out put dir
    ddir  = $$2

    log($$DESTDIR)
    for(FILE, files) {
        DDIR = $$DESTDIR$$ddir
        #check dir is exist
        #QMAKE_POST_LINK += echo $$FILE $$escape_expand(\\n\\t)
        #message(FILE $$FILE)
        !exists($$DDIR) {
            log($$DDIR not exists)
            mkpath($$DDIR)
        }
        win32:DDIR ~= s,/,\\,g
        win32:FILE ~= s,/,\\,g
        #log($$QMAKE_COPY $$quote($$FILE) $$quote($$DDIR) $$escape_expand(\\n\\t))
        QMAKE_POST_LINK += $$QMAKE_COPY $$quote($$FILE) $$quote($$DDIR) $$escape_expand(\\n\\t)
        #QMAKE_POST_LINK += echo $$FILE $$escape_expand(\\n\\t)
        #message(FILE $$FILE)
    }
    #QMAKE_POST_LINK += echo $$quote($$PWD  == $$DESTDIR)
    #message(LINK: $$QMAKE_POST_LINK)
    export(QMAKE_POST_LINK)
    return(true)
}

#-------------------------------------------------
# AUTO GENERATE VERSION NO
#-------------------------------------------------

isEmpty(MAJOR_VERSION_NUMBER) {
    MAJOR_VERSION_NUMBER = 1
}

if(contains(DEFINES, MAPLE_AUTO_GENERATE_VERSION_NO)){
    win32{
        VERSION = $${MAJOR_VERSION_NUMBER}.$$system(build_number.bat)
    }

    unix{
        VERSION = $${MAJOR_VERSION_NUMBER}.$$system(date +%y.%m%d)
    }

    DEFINES += APP_VERSION=\\\"$$VERSION\\\"
    DEFINES += APP_NAME=\\\"$$TARGET\\\"
}



